﻿using EditoneLib.Annotations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace EditoneLib
{
    public class Settings : Dictionary<string, dynamic>, INotifyPropertyChanged
    {
        // we only process 48kHz PCM audio
        public const int SampleRate = 48000;

        // IEEE float
        public const int SampleSize = sizeof (float);

        public Settings()
            : base()
        {
            this["Volume"] = 1.0;
        }


        public event PropertyChangedEventHandler PropertyChanged;

        public new dynamic this[string x]
        {
            get { return base[x]; }
            set
            {
                base[x] = value;
                OnPropertyChanged(x);
            }
        }

        // Todo: remove
        public static long ToSampleCount(TimeSpan time)
        {
            return time.Ticks/(10000000/SampleRate);
        }

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}